package com.xinxing.learning.batch.util;

import cn.hutool.core.date.DateUtil;
import com.xinxing.learning.batch.common.SyncConstants;
import com.xinxing.learning.batch.entity.CdcTemp;
import com.xinxing.learning.batch.entity.User;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;

public class JobUtil {

    /**
     * 传递参数:
     * https://blog.csdn.net/weixin_45357522/article/details/110651906
     * https://blog.csdn.net/lewenson/article/details/120179510
     *
     * @return
     */
    public static JobParameters makeJobParameters() {
        User user = new User();
        user.setPhone("13678900987");
        user.setTitle("test");
        user.setName("张三");
        user.setEmail("test@qq.com");
        JobParameters jobParameters = new JobParametersBuilder()
                .addLong("time", System.currentTimeMillis())
                .addString("user", user.toString())
                .toJobParameters();

        return jobParameters;
    }

    public static JobParameters makeJobParameters(CdcTemp currentCdcTemp) {
        String lastUpdateTime = DateUtil.formatDateTime(currentCdcTemp.getLastUpdateTime());
        JobParameters jobParameters = new JobParametersBuilder()
                .addLong("time", System.currentTimeMillis())
                .addString(SyncConstants.STR_LAST_UPDATE_TIME, lastUpdateTime)
                .toJobParameters();
        return jobParameters;
    }
}
